<?php

namespace app\xiaohongshu\controller;


use app\common\controller\XiaohongshuApi;
use app\xiaohongshu\service\XhsService;

class Xiaohongshu extends XiaohongshuApi
{
    public function get()
    {
        // 验证URL参数是否存在
        $link = $this->request->param('link');
        if (empty($link)) {
            return $this->error('link不能为空');
        }

        $xhsService = new XhsService();

        // 解析用户ID
        $id = $xhsService->analyzeUrl($link);
      
        if (empty($id)) {
            return $this->error('无效的小红书URL');
        }
        

        // 获取用户信息
        $data = $xhsService->getUserInfo($id);
        if ($data === false) {
            return $this->error('获取用户信息失败');
        }

        return $this->success('获取成功', $data);
    }
}
